//
//  NvTransitionsCell.m
//  NvSellerShowSDK
//
//  Created by 刘志雄 on 2017/10/15.
//  Copyright © 2017年 roc. All rights reserved.
//

#import "NvTransitionsCell.h"
#import "Utils/Utils.h"
@interface  NvTransitionsCell()

@property(nonatomic,strong)UIImageView *imageView;
@property(nonatomic,strong)UILabel *titleLabel;
@property(nonatomic,strong) UIView *imageBackView;

@end

@implementation NvTransitionsCell

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}

-(void)setupUI{
    
    self.imageBackView = [[UIView alloc]init];
    [self.contentView addSubview:self.imageBackView];
    [self.imageBackView setBackgroundColor:UIColorRGB(241, 241, 241)];
    [self.imageBackView.layer setMasksToBounds:YES];
    [self.imageBackView.layer setCornerRadius:5];
    [self.imageBackView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left);
        make.right.equalTo(self.contentView.mas_right);
        make.top.equalTo(self.contentView.mas_top);
        if (IPHONE5) {
            make.height.equalTo(@55);
        }else{
            make.height.equalTo(@85);
        }
    }];
    
    self.imageView = [[UIImageView alloc]init];
    [self.imageView setContentMode:UIViewContentModeScaleAspectFit];
    [self.contentView addSubview:self.imageView];
    [self.imageView setBackgroundColor:UIColorRGB(241, 241, 241)];
    [self.imageView.layer setMasksToBounds:YES];
    [self.imageView.layer setCornerRadius:5];
    [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView.mas_centerY).offset(-10);
        make.centerX.equalTo(self.contentView.mas_centerX);
        make.width.equalTo(@35);
        make.height.equalTo(@32);
    }];
    
    self.titleLabel = [[UILabel alloc]init];
    [self.titleLabel setFont:[UIFont systemFontOfSize:14]];
    [self.titleLabel setTextAlignment:NSTextAlignmentCenter];
    [self.contentView addSubview:self.titleLabel];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left);
        make.right.equalTo(self.contentView.mas_right);
        make.height.equalTo(@20);
        make.bottom.equalTo(self.contentView.mas_bottom);
    }];
}

-(void)setModel:(NvTransitionsModel *)model{
    [self.imageView setImage:[UIImage imageFromBundle:model.imageName]];
    [self.titleLabel setText:model.transitionSeeName];
    if (model.isSelected) {
        self.imageBackView.layer.borderWidth = 2;
        self.imageBackView.layer.cornerRadius = 5;
        self.imageBackView.layer.borderColor = UIColorRGB(96, 194, 227).CGColor;
    }else{
        self.imageBackView.layer.borderWidth = 0;
    }
}

@end
